package com.example.demo.web.controller;

import com.example.demo.core.handler.exception.ResultBO;
import com.example.demo.core.handler.exception.ResultTool;
import com.example.demo.sys.service.DeptService;
import com.example.demo.sys.service.bo.DepartmentBO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/")
public class DeptController {
    @Autowired
    private DeptService deptService;

    @GetMapping("/dept")
    @ResponseBody
    public ResultBO<?> getDepts(){
        List<DepartmentBO> result = deptService.getAllDepartments();
        return ResultTool.success(result);
    }

    @PostMapping("/dept")
    @ResponseBody
    public ResultBO<?> getDepts(@RequestBody DepartmentBO departmentBO){
        deptService.addDepartment(departmentBO);
        return ResultTool.success(departmentBO);
    }
}
